﻿using MES.Desktop.Common;
using MES.Desktop.IService;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES.Desktop.SystemModule.Models
{
    public class PostModel : DataModelBase
    {
        public PostModel() { }

        IPostService _postService;
        public PostModel(IPostService postService)
        {
            _postService = postService;
        }
        private bool _isSelected;

        public bool IsSelected
        {
            get { return _isSelected; }
            set { SetProperty<bool>(ref _isSelected, value); }
        }

        public int Index { get; set; }

        public int PostId { get; set; }

        private string _postName;

        public string PostName
        {
            get { return _postName; }
            set
            {
                SetProperty<string>(ref _postName, value);

                this.ClearErrors();
                if (string.IsNullOrEmpty(_postName))
                {
                    this.RaiseErrors("职位名不能为空");
                }
                if (_postService != null && _postService.CheckName(value, PostId))
                {
                    this.RaiseErrors("职位名不能重复");
                }
            }
        }

    }
}
